#!/bin/bash
if [ ! -f "ILSVRC2012_img_train.tar" ];then
echo "ILSVRC2012_img_train.tar no exist"
exit
fi
if [ ! -f "ILSVRC2012_img_val.tar" ];then
echo "ILSVRC2012_img_val.tar no exist"
exit
fi
#if [ -d "./train" ];then
#rm -rf ./train
#fi
#if [ -d "./val" ];then
#rm -rf ./val
#fi

mkdir -p train val 
tar -xvf ILSVRC2012_img_train.tar -C train/
tar -xvf ILSVRC2012_img_val.tar -C val/
cd train/
find . -name "*.tar" | while read LINE ; do mkdir -p "${LINE%.tar}"; tar -xvf "${LINE}" -C "${LINE%.tar}"; rm -f "${LINE}"; done
cd ..
if [ -d "ImageNet2012Preprocess" ]
then
python3  ImageNet2012Preprocess/preprocess_imagenet_validation_data.py val/ ImageNet2012Preprocess/imagenet_2012_validation_synset_labels.txt
else
python3  ImageNet2012Preprocess-master/preprocess_imagenet_validation_data.py val/ ImageNet2012Preprocess-master/imagenet_2012_validation_synset_labels.txt
fi
echo "train standard number:1281167"
train_number=$(ls -lR train/ |grep "^-" |wc -l)
echo "train number true:$train_number"
val_number=$(ls -lR val/ |grep "^-" |wc -l)
echo "val standard number:50000"
echo "val ture number:$val_number"